package com.base.core.common.utils;


import com.base.core.model.UserInfo;

public class UserContext {
    private static final ThreadLocal<UserInfo> currentUser = new ThreadLocal<>();

    public static void setCurrentUser(UserInfo userInfo) {
        currentUser.set(userInfo);
    }
    public static UserInfo getCurrentUser() {
        return currentUser.get();
    }

    public static Long getCurrentUserId() {
        UserInfo userInfo = currentUser.get();
        return userInfo != null ? userInfo.getId() : null;
    }

    public static void clear() {
        currentUser.remove();
    }
}
